import QtQuick 2.9
import QtQuick.Window 2.2

Item {
    id: root
    width: Screen.width
    height: Screen.height

    property var _OBJS_FLY: new Array
    property var _OBJS_POOL: new Array

    property real moveXTime: 0
    property real moveYTime: 0

    property bool isFirst: true

    property real gMouseX: 0
    property real gMouseY: 0

    function createInstance(mx, my)
    {
        var obj = undefined
        if(_OBJS_POOL.length > 0)
        {
            obj = _OBJS_POOL[0]
            _OBJS_POOL.splice(0, 1)
//            console.log("_OBJS_POOL len: ", _OBJS_POOL.length)
        }
        else{
            obj = Qt.createComponent("MyMulti.qml").createObject(root)
        }

        if(obj === undefined) return

        obj.startX = mx
        obj.startY = my
        obj.fly()
    }

    function getRandom(value)
    {
        Math.seed = (new Date).toLocaleString()
        var r = Math.random()
        var index = Math.floor(value * r)
        return index
    }

    Connections{
        target: widget
        onNotifyMsg:
        {
            createInstance(mx, my)
        }
        onNotifyMousePos:
        {
//            if(isFirst)
//            {
//                isFirst = false
//                par.emitter.x = mx
//                par.emitter.y = my
//                return
//            }

//            moveXTime = Math.abs(mx - par.x) / Screen.width * 300
//            moveYTime = Math.abs(my - par.y) / Screen.height * 300
//            par.emitter.x = mx
//            par.emitter.y = my

            gMouseX = mx
            gMouseY = my
        }
    }

    // 移动的多边形
    MyNodes{
        id: nodes
    }

    // 粒子特效
//    MyParticle{
//        id: par

//        Behavior on emitter.x {
//            NumberAnimation{ duration: moveXTime; }
//        }
//        Behavior on emitter.y {
//            NumberAnimation{ duration: moveYTime; }
//        }
//    }

}
